//创建敌人模型
var score = document.getElementById("score");
function EnemyModelClass(x,y,width,height,blood,speed,type,sumStatus){
	//1.敌人的坐标信息
	//敌人的位置x，y 大小 width height 血量blood 速度 speed 类型 type
	//1.敌人的坐标信息
	this.x = x;
	this.y = y;
	//2.敌人的宽度和高度
	this.width = width;
	this.height = height;
	//敌人的血量
	this.blood = blood;
	//敌人的速度
	this.speed = speed;
	//敌人的类型
	this.type = type;
	//敌人的类型
	this.img = new Image;
	this.img.src = "../playplane_team11/img/"+type+".png";
	//用来记录敌人是否已经死亡
	this.Die = false;
	//用来记录飞机的状态
	this.status = 0;
	//用来记录总的变化状态的数量
	this.sumStatus = sumStatus;
	
}
//随机一个整数 // 获取随机机敌人
function randNumber(min,max){
	return parseInt(Math.random()*(max-min+1)+min);
}
//开始创建
function EnemyControllerClass(){
	//创建保存敌人的数组
	this.enemyArray = [];
	
	//创建并显示
	this.createAndShowEnemy = function(){
		//创建一个敌人
		var num = randNumber(1,300);
		
		if(num>20 && num <26){
			var enemy1 = new EnemyModelClass(randNumber(0,canvas.width-38),-38,38,38,1,randNumber(2,5),"enemy1",5);
			this.enemyArray.push(enemy1);
		}
		if(num>2&&num<3.5){
			var enemy2 = new EnemyModelClass(randNumber(0,canvas.width-110),-164,110,164,6,randNumber(2,4),"enemy2",10);
			this.enemyArray.push(enemy2);
		}
		if(num >5 && num <7){
			var enemy3 = new EnemyModelClass(randNumber(0,canvas.width -46),-64,46,64,4,randNumber(2,4),"enemy3",6);
			this.enemyArray.push(enemy3);
		}
		for (var i= 0;i<this.enemyArray.length;i++) {
			if(this.enemyArray[i].y>canvas.height){
				this.enemyArray.splice(i,1);
				continue;
			}
			if(this.enemyArray[i].isDie){
				this.enemyArray[i].status++;
					
				if(this.enemyArray[i].status>this.enemyArray[i].sumStatus){
					
				    if(this.enemyArray[i].type == "enemy1" ){
		            SUMSCORE+=10;
	                 }
	                if(this.enemyArray[i].type == "enemy2"){
		            SUMSCORE+=30;
	                 }
	                 if(this.enemyArray[i].type == "enemy3"){
		             SUMSCORE+=20;
	                 }
	                 $("#score").html("分数:"+ SUMSCORE);
	                 this.enemyArray.splice(i,1);
					continue;
		
					
					
					
				}
			}
			this.enemyArray[i].y += this.enemyArray[i].speed;
			//绘制敌人
			context.beginPath();
			context.drawImage(this.enemyArray[i].img,this.enemyArray[i].status*this.enemyArray[i].width,0,this.enemyArray[i].width,this.enemyArray[i].height,this.enemyArray[i].x,this.enemyArray[i].y,this.enemyArray[i].width,this.enemyArray[i].height);
			context.save();
		}
		
		
		
	}
	
}
